﻿/*---------------------------------------------------------------------*/
// fileName="NotifyWinPresenter.cs" CompanyName="SureKAM"
// Copyright SureKAM (c). All right reserved.
/*---------------------------------------------------------------------*/

namespace SureKAM.BackUp.Notify.Presenter
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using SureKAM.BackUp.Notify.Presenter.Interfaces;
    using SureKAM.BackUp.Notify.Presenter.ViewInterfaces;
    using SureKAM.BackUp.Notify.Service.Interfaces;

    public class NotifyWinPresenter:INotifyWinPresenter
    {
        #region 私有字段
        private INotifyWinView iNotifyWinView;
        private INotifyService iNotifyService;
        #endregion

        #region 构造
        /// <summary>
        /// 构造方法
        /// </summary>
        /// <param name="iNotifyWinView">Notify Win View</param>
        /// <param name="iNotifyService">notify Service</param>
        public NotifyWinPresenter(INotifyWinView  iNotifyWinView,INotifyService iNotifyService)
        {
            this.iNotifyWinView = iNotifyWinView;
            this.iNotifyService = iNotifyService;
        }
        #endregion

        #region 私有方法
        /// <summary>
        /// 添加数据 
        /// </summary>
        /// <param name="notify"></param>
        /// <returns></returns>
        private bool  Add(Domain.Notify notify)
        {
            if (!string.IsNullOrEmpty(this.iNotifyService.Add(notify))) return true;
            return false;
        }

        /// <summary>
        /// 刷新
        /// </summary>
        /// <returns></returns>
        private List<Domain.Notify> Reflush()
        {
            return this.iNotifyService.GetNotifies();
        }
        
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="currentId"></param>
        /// <returns></returns>
        private  bool  Delete(string currentId)
        {
            Domain.Notify notify = this.iNotifyService.GetNotifyById(currentId);
            if (notify != null && !String.IsNullOrEmpty(this.iNotifyService.Delete(notify))) return true;
            return false;
        }

        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="notify"></param>
        /// <returns></returns>
        private  bool  Update(Domain.Notify notify)
        {
            if (notify != null && this.iNotifyService.Update(notify)!=null) return true;
            else return false;
        }
        #endregion

        #region 公有方法
        /// <summary>
        /// 初始化
        /// </summary>
        public void Init()
        {
            this.iNotifyWinView.DataBindGrid(this.iNotifyService.GetNotifies());
            this.iNotifyWinView.notifyAdd = Add;
            this.iNotifyWinView.reflush = this.Reflush;
            this.iNotifyWinView.notifyDelete = Delete;
            this.iNotifyWinView.notifyUpdate = Update;
        }
        #endregion
       
    }
}
